<template>
	<view class="attendance_info">
		<view class="header">
			<view class="pic">
				{{pic}}
			</view>
			<view class="text">
				<view class="name">
					{{ userInfo.name }}
				</view>
				<view class="rule">
					考勤组：{{ attendance_info.name }}
				</view>
			</view>
		</view>
		<view class="info">
			<uni-collapse-item title="考勤时间">
				<view class="content" style="margin-left: 20rpx;">
					<view class="text">
						<text v-for="item in timeArr" :key="item" style="margin-right: 20rpx;">
							{{ item }}
						</text>
					</view>
					<view class="time">
						<text>上班时间：{{ attendance_info.startWork }} - {{ attendance_info.endWork }}</text>
					</view>
				</view>
			</uni-collapse-item>
			<uni-collapse-item title="打卡规则">
				<view class="content" style="margin-left: 20rpx;">
					<view>打卡位置：{{ town_info.town_address }}</view>
					<view>打卡范围：{{ town_info.town_range }} 米</view>
					<view>
						弹性规则：
					</view>
					<view style="margin-left: 40rpx;">
						上班晚到{{ attendance_info.intervalTime }}分钟不算迟到
					</view>
					<view style="margin-left: 40rpx;">
						下班早走{{ attendance_info.intervalTime }}分钟不算早退
					</view>
				</view>
			</uni-collapse-item>

		</view>
	</view>
</template>

<script>
	import { idAttendance,idToTown } from '@/api/attendance.js'
	
	export default {
		data() {
			return {
				attendance_id: null,
				attendance_info: null,
				town_info:null,
				userInfo: null,
				pic: null,
				town_id:null,
				timeArr:[]
			}
		},
		onLoad(option) {
			this.init()
		},
		created() {
			
		},
		methods: {
			async init() {
				this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
				this.pic = this.userInfo.name.slice(this.userInfo.name.length - 2, this.userInfo.name.length)
				const obj = {
					id: this.attendance_id
				}
				this.attendance_info = JSON.parse(uni.getStorageSync('attendanceInfo'))
	
				this.town_info = JSON.parse(uni.getStorageSync('townInfo'))
					console.log(this.attendance_info,this.town_info);
							this.updateField()
			},
			updateField(){
				const time = this.attendance_info.attendanceTime.split(',')
				time.forEach(item=>{
					if(item == 1){
						this.timeArr.push('周一')
					}else if(item == 2){
						this.timeArr.push('周二')
					}else if(item == 3){
						this.timeArr.push('周三')
					}else if(item == 4){
						this.timeArr.push('周四')
					}else if(item == 5){
						this.timeArr.push('周五')
					}else if(item == 6){
						this.timeArr.push('周六')
					}else if(item == 7){
						this.timeArr.push('周日')
					}
				})
			},
		}
	}
</script>


<style lang="less" scoped>
	.attendance_info {
		padding: 20rpx;

		.header {
			display: flex;

			.pic {
				font-size: 30rpx;
				padding: 18rpx;
				background-color: blue;
				width: 60rpx;
				height: 60rpx;
				text-align: center;
				line-height: 60rpx;
				color: #ffffff;
				border-radius: 54rpx;
			}

			.text {
				display: block;
				margin-left: 40rpx;

				.name {
					text-align: center;
				}
			}

		}
	}
</style>
